import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
// import { rules } from '/@/utils/helper/validator';
// import { render } from '/@/utils/common/renderUtils';
// import { getWeekMonthQuarterYear } from '/@/utils';
import { usePermission } from '/@/hooks/web/usePermission';
const { isDisabledAuth } = usePermission();
//列表数据
export const columns: BasicColumn[] = [
  {
    title: '请假人',
    align: 'center',
    dataIndex: 'name',
  },
  {
    title: '性别',
    align: 'center',
    dataIndex: 'sex_dictText',
  },
  {
    title: '年龄',
    align: 'center',
    dataIndex: 'age',
  },
  {
    title: '请假天数',
    align: 'center',
    dataIndex: 'days',
  },
  {
    title: '开始时间',
    align: 'center',
    dataIndex: 'startDate',
    customRender: ({ text }) => {
      text = !text ? '' : text.length > 10 ? text.substr(0, 10) : text;
      return text;
    },
  },
  {
    title: '结束时间',
    align: 'center',
    dataIndex: 'endDate',
    customRender: ({ text }) => {
      text = !text ? '' : text.length > 10 ? text.substr(0, 10) : text;
      return text;
    },
  },
  {
    title: '请假原因',
    align: 'center',
    dataIndex: 'descc',
  },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: '请假人',
    field: 'name',
    component: 'Input',
    //colProps: {span: 6},
  },
  {
    label: '性别',
    field: 'sex',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'sex',
    },
    //colProps: {span: 6},
  },
  {
    label: '年龄',
    field: 'age',
    component: 'InputNumber',
    //colProps: {span: 6},
  },
  {
    label: '开始时间',
    field: 'startDate',
    component: 'DatePicker',
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
    },
    //colProps: {span: 6},
  },
  {
    label: '结束时间',
    field: 'endDate',
    component: 'DatePicker',
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
    },
    //colProps: {span: 6},
  },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '请假人',
    field: 'name',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入请假人!' }];
    },
  },
  {
    label: '性别',
    field: 'sex',
    component: 'JDictSelectTag',
    auth: 'qingjia:qingjia:sex',
    componentProps: {
      dictCode: 'sex',
    },
  },
  {
    label: '年龄',
    field: 'age',
    component: 'InputNumber',
    dynamicDisabled: ({ values }) => {
      return isDisabledAuth('qingjia:qingjia:age');
    },
  },
  {
    label: '请假天数',
    field: 'days',
    component: 'InputNumber',
  },
  {
    label: '开始时间',
    field: 'startDate',
    component: 'DatePicker',
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
    },
  },
  {
    label: '结束时间',
    field: 'endDate',
    component: 'DatePicker',
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
    },
  },
  {
    label: '请假原因',
    field: 'descc',
    component: 'InputTextArea',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入请假原因!' }];
    },
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];

// 高级查询数据
export const superQuerySchema = {
  name: { title: '请假人', order: 0, view: 'text', type: 'string' },
  sex: { title: '性别', order: 1, view: 'list', type: 'string', dictCode: 'sex' },
  age: { title: '年龄', order: 2, view: 'number', type: 'number' },
  days: { title: '请假天数', order: 3, view: 'number', type: 'number' },
  startDate: { title: '开始时间', order: 4, view: 'date', type: 'string' },
  endDate: { title: '结束时间', order: 5, view: 'date', type: 'string' },
  descc: { title: '请假原因', order: 6, view: 'textarea', type: 'string' },
};

/**
 * 流程表单调用这个方法获取formSchema
 * @param param
 */
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
